package com.teach_sys.utils;

import org.apache.commons.beanutils.BeanUtils;

import java.util.Map;

public class WebUtils {
    /**
     * 把Map中的值注入到对应的JavaBean属性中
     *
     * @param value 传进来的Map参数
     * @param bean  需要注入的Bean对象
     */
    public static <T> T copyParamToBean(Map value, T bean) {
        try {
            BeanUtils.populate(bean, value);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return bean;
    }

//    public static Student copyParamToStudent(HttpServletRequest request) {
//        String sno = request.getParameter("Sno");
//        String sname = request.getParameter("Sname");
//        String ssex = request.getParameter("Ssex");
//        int sage = Integer.parseInt(request.getParameter("Sage"));
//        String sdept = request.getParameter("Sdept");
//        return new Student(sno, sname, ssex, sage, sdept);
//    }
//
//    public static Course copyParamToCourse(HttpServletRequest request) {
//        String cno = request.getParameter("Cno");
//        String cname = request.getParameter("Cname");
//        String cpno = request.getParameter("Cpno");
//        int ccredit = Integer.parseInt(request.getParameter("Ccredit"));
//        return new Course(cno, cname, cpno, ccredit);
//    }
//
//    public static SC copyParamToSC(HttpServletRequest request) {
//        String sno = request.getParameter("Sno");
//        String cno = request.getParameter("Cno");
//        int grade = Integer.parseInt(request.getParameter("Grade"));
//        return new SC(sno, cno, grade);
//    }
}
